# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Thomas Kienlen <kommander@laposte.net>
pkgname=flightgear
pkgver=2020.3.13
_pkgver=${pkgver%.*}
pkgrel=0
pkgdesc="Flight Gear Flight Simulator"
url="http://flightgear.org"
arch="all !riscv64 !x86 !armhf !armv7" # limited by openscenegraph and build compatibility
license="GPL-2.0-or-later"
makedepends="
	boost-dev
	cmake
	curl-dev
	dbus-dev
	eudev-dev
	freeglut-dev
	glew-dev
	libexecinfo-dev
	libx11-dev
	libxi-dev
	libxmu-dev
	mesa-dev
	openal-soft-dev
	openscenegraph-dev
	plib
	qt5-qtbase-dev
	qt5-qtdeclarative-dev
	qt5-qtsvg-dev
	simgear-dev=~$pkgver
	zlib-dev
	"
install="$pkgname.post-install"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
options="!check" # FIXME test suite does not get built
source="
	https://downloads.sourceforge.net/project/flightgear/release-$_pkgver/flightgear-$pkgver.tar.bz2
	musl-fenv.patch
	musl-fix_error_h.patch
	musl-fix_feenableexcept.patch
	musl-fix_fpos_t.patch
	musl-include-fcntl.patch
	musl-fix_backtrace.patch
	flightgear-data-downloader.sh
	"

build() {
	cmake \
		-D BUILD_TESTING=ON \
		-D CMAKE_BUILD_TYPE="Release" \
		-D CMAKE_EXE_LINKER_FLAGS=-lexecinfo \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_SYSCONFDIR=/etc/$pkgname \
		-D FG_DATA_DIR=/var/lib/$pkgname \
		-D SimGear_DIR=/usr/lib/cmake/SimGear \
		.
	make
}

check() {
	make test
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/flightgear-data-downloader.sh "$pkgdir"/usr/bin/flightgear-data-downloader
}

sha512sums="
4623af52c0c1fd86ab2bf32bf95bc7be1bc4f867927b7f2ff1d453a4b6e5dbe4c4c094dd23050133e00b3d6b904f77fac396e0d093a99692d18c47823d637f7f  flightgear-2020.3.13.tar.bz2
81ffb1ecfceae8d4ebb14717fb785118b3c290171245762cb4ab85be769582576147fe1b1b60fe854f4dd8079ebaf913da1585809ba9048d55f8710159c05614  musl-fenv.patch
b477510a102b0d01859ab39ddf7b5c4bcd3b80aa522320b2128095228b643d5e067dd61f8edbef7df7ed1a35aea647444126ba58eb39a82d294ae8a0f6e808e5  musl-fix_error_h.patch
29d12098c2581122234188cadd929238c41258bf347de2fcd30dabb46e398d19566e064b2a4267370bf7669c5dcde2c87ef1232b7b1a9ed27ad7885a26378b05  musl-fix_feenableexcept.patch
3a5d280bcd806fbdeb7b2f92435ffa7b44c420494ae658060624dfa34709a2b36448c1ca8c81bff1e4bb2878fa55200eb69535699062aff5286c7f640fbc3081  musl-fix_fpos_t.patch
89f871216cac9bf772c6f7a4d12d79ff73a38179547464ffa93ed24394309cb085719c0de5e2a82e2086e994cbf886a8763e4c577fdda476ddbab0e3e3dea4cd  musl-include-fcntl.patch
c9d680759fc163366d352bf7b96850a71303b427b0664a50e6ebc7bb11a2d4910cc18988cbc9c305f8a18307c8c2d739559a9358f7f682b34a5b41a126f35567  musl-fix_backtrace.patch
e1e88f99e3ef2f6019e9f023ade8be40a2c509642a85ba6889746d9488c34d6a92eb0a045d9fc1d7e465c53dccd337a4506d6a91c6e9e5e09f4e39d75a4ce3be  flightgear-data-downloader.sh
"
